package cn.pconline.autoclub.util.ubb.node;

import cn.pconline.autoclub.util.ubb.EscapeUtils;
import cn.pconline.autoclub.util.ubb.Node;

/**
 *
 * @author xhchen
 */
public class HideNode4Wap extends AbstractNode {
	String contribution = "贡献值";

	public HideNode4Wap() {}

	private HideNode4Wap(String name, String attribute) {
		super.name = name;
		super.attribute = attribute;
	}

	public void setContribution(String contribution) {
		this.contribution = contribution;
	}

	@Override
	public StringBuilder getText(java.util.LinkedList<Node> stack) {
		StringBuilder sb = new StringBuilder();

		int limit = -1;
		if (attribute != null) {
			try {
				limit = Integer.parseInt(attribute);
			} catch (Exception ex) {}
		}
		if ("hide".equals(name)) {
			sb.append("<div class=\"hidden\">您好！本部分内容");
			if (limit > 0) {
				sb.append(contribution).append("大于").append(limit);
			} else {
				sb.append("回复");
			}
			sb.append("可见</div>");

		} else if ("_hide_".equals(name)) {
			sb.append("<div class=\"show\">****以下为");
			if (limit > 0) {
				sb.append(contribution).append("大于").append(limit);
			} else {
				sb.append("回复");
			}
			sb.append("可见内容****</div>");

			sb.append(text);

			sb.append("<div class=\"show\">****************</div>");
		}

		return sb;
	}

	@Override
	public void appendText(CharSequence text) {
		EscapeUtils.appendHtml(text, super.text);
	}

	@Override
	public Node copyWithoutText() {
		return new HideNode4Wap(name, attribute);
	}

	@Override
	public Node build(String name, String attribute) {
		return new HideNode4Wap(name, attribute);
	}

}
